package com.yunding.interceptor;


//import com.yunzheng.common.BaseResult;
//import com.yunzheng.constants.SystemConstants;
//import com.yunzheng.enums.ResultStatuesEnums;
//import com.yunzheng.redis.RedisManager;
//import com.yunzheng.util.MapperUtil;

import lombok.extern.slf4j.Slf4j;


/**
 * @author: 郭思良
 * @date: 2020/3/11 9:14
 */

@Slf4j
public class MyAuthFilter {
//    extends FormAuthenticationFilter
//
//    public static final String NULL = "null";
//
//    public <T> T getBean(Class<T> clazz, HttpServletRequest request){
//        WebApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
//        return applicationContext.getBean(clazz);
//    }
//
//    @Override
//    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
//        return false;
//    }
//
//
//    @Override
//    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
//
//        Subject currentUser = SecurityUtils.getSubject();
//        HttpServletRequest req = (HttpServletRequest)request;
//        HttpServletResponse res = (HttpServletResponse) response;
//
//        RedisManager redisManager = getBean(RedisManager.class,req);
//
//        String token = req.getHeader(SystemConstants.TOKEN);
//
//        //没有传token
//        if (StringUtils.isBlank(token)){
//            res.setCharacterEncoding("UTF-8");
//            res.setContentType("application/json");
//            res.getWriter().print(MapperUtil.obj2json(BaseResult.notOk(ResultStatuesEnums.NOT_LOGIN)));
//            return false;
//        }
//
//        //token不存在
//        String userId = String.valueOf(redisManager.get(token));
//        if (StringUtils.isBlank(userId) || NULL.equals(userId)){
//            res.setCharacterEncoding("UTF-8");
//            res.setContentType("application/json");
//            res.getWriter().print(MapperUtil.obj2json(BaseResult.notOk(ResultStatuesEnums.BAD_TOKEN)));
//            return false;
//        }
//        // TODO: 2020/8/11 解决shiro登录之后仍然是false的问题
//        //token没有认证
//        if (!currentUser.isAuthenticated()){
//            res.setCharacterEncoding("UTF-8");
//            res.setContentType("application/json");
//            res.getWriter().print(MapperUtil.obj2json(BaseResult.notOk(ResultStatuesEnums.BAD_TOKEN)));
//            return false;
//        }
//
//        return true;
//    }
}
